#include<stdio.h>
#include<stdlib.h>

typedef struct Node
{
	int data;
	struct Node *next;
}*List;

List merge(List head1,List head2)  //按升序合并为一个链表
{
	List p=head1->next,q=head2->next;
	List newHead=(List)malloc(sizeof(struct Node));
	List k=newHead;
	while(p&&q){
		if(p->data<q->data){
			k->next=p;
			k=p;
			p=p->next;
		}
		else if(p->data>q->data){
			k->next=q;
			k=q;
			q=q->next;
		}
		else{
			k->next=p;
			k=p;
			p=p->next;
			q=q->next;
			
		}
	}
	if(p){
		k->next=p;
	}
	if(q){
		k->next=q;
	}
	return newHead;
}

merge(List headA,List headB){
	List p=headA->next,q=headB->next;
	List headC=(List)malloc(sizeof(struct Node));
	k=headC;
	while(p&&q){
		if(p->data<q->data){
			k->next=p;
			k=p;
			p=p->next;
		}
		else if(p->data>q->data){
			k->next=q;
			k=q;
			q=q->next;
		}else{
			k->next=p;
			k=p;
			p=p->next;
			q=q->next;
		}
	}
	if(p){
		k->next=p;
	}
	if(q){
		k->next=q;
	}
	return headC;
}
List create_list(List head){
	if(head == NULL){
		head=(List)malloc(sizeof(struct Node));
		head->next=NULL;
	}
	List p=head;
	int x;
	scanf("%d",&x);
	while(x!=-1){
		List node=(List)malloc(sizeof(struct Node));
		node->data=x;
		node->next=p->next;
		p->next=node;
		p=node;
		scanf("%d",&x);
	}
	p->next=NULL;
	return head;
}
void printL(List head){
	List p=head->next;
	while(p){
		printf("%d->",p->data);
		p=p->next;
	}
}
int main(){
	List headA=NULL;
	List headB=NULL;
	headA=create_list(headA);
	headB=create_list(headB);
	List head=merge(headA,headB);
	printL(head);
	return 0;
}